/*
  Copyright © 2010  Vinícius dos Santos Oliveira

      This file is part of Touché.

      Touché is free software: you can redistribute it and/or modify
      it under the terms of the GNU Lesser General Public License as published
      by the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU Lesser General Public License for more details.

      You should have received a copy of the GNU Lesser General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

#ifndef AUDIOELEMENT_H
#define AUDIOELEMENT_H

#include "toucheelement.h"
#ifndef TOUCHE_SHOULD_SKIP_THIS
#include <gst/gst.h>
#endif

#include <stdint.h>

#include <QTimer>

#ifndef TOUCHE_SHOULD_SKIP_THIS

class LineEditItem: public QGraphicsTextItem
{
    QString &string;

protected:
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    void focusOutEvent(QFocusEvent *event);

public:
    LineEditItem(QString &string, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
};

void on_pad_added(GstElement *element, GstPad *source_pad, gpointer data);

#endif

namespace Touche {

    class AudioElement : public Element
    {
        Q_OBJECT

#ifndef TOUCHE_SHOULD_SKIP_THIS
        friend void ::on_pad_added(GstElement *element, GstPad *source_pad, gpointer data);
#endif

        static quint32 counter;
        static int count;
        static bool recording;
        static bool playing;
        static QTimer onPlayFinish;

#ifndef TOUCHE_SHOULD_SKIP_THIS
        static GstElement *pipelines[2];
        static GstElement *fileSrc;
        static GstElement *fileSink;
#else
        static void *pipelines[2];
        static void *fileSrc;
        static void *fileSink;
#endif

        bool locked;
        QVector<QString> m_options;
        QString fileName;
        QString description;
        QGraphicsItem *m_item;
        QGraphicsTextItem *m_descriptionItem;

    public:
        AudioElement();
        ~AudioElement();
        const QString &type() const;
        QRectF item(QGraphicsItem *parentItem) const;
        QVector<QString> menuOptions() const;

    private slots:
        // onPlayFinish

    public slots:
        void onMenuActived(const QString &option);
        void onSceneReceived(QGraphicsScene *scene);
        void onElementLocked(bool locked);

    public slots:
        void stopEditionMode();

    signals:
        void playerChanged(AudioElement *);
    };

} // namespace Touche

#endif // AUDIOELEMENT_H
